// JavaScript Document

$(function(){  
	     // alert("bb");
	     // var user='<%=session["username"]%>'; 
	      //var id = '<%=Session["UserName"] %>';
		  //var user = ${sessionScope.username};
	      //var pw= session.getAttribute("password");
	     // var role= session.getAttribute("role");
	     // alert(user);
	    //当载入页面时，获取cookie中的用户信息，若存在，则检查其正确性，若存在且正确则跳转，否则就留在登陆界面。
//	   if(user != null && ss != null) {
//		   $.post('jsp/user/login.jsp', 'action=login&username='+username+'&password='+password+'&role='+role, function(data) {
//				json = eval('('+data+')');
//				var res = json.result;
//				//alert(res);
//				if (res == "admintrue") {
//					window.location = "manage.jsp";
//				}else if(res == "workertrue"){
//					window.location = "worker.jsp?name="+username;
//			    }else if(res =="false") { 
//					alert("用户名或密码错误，请重新输入");
//				}
//			});
//	 }
});

function login() {
	var username = $("input[name='username']").val();
	var password = $("input[name='password']").val();
	var role=$("select[name='role']").val();
	//alert(username+password+role+username);
	$.post('jsp/user/login.jsp', 'action=login&username='+username+'&password='+password+'&role='+role, function(data) {
		json = eval('('+data+')');
		var res = json.result;
		//alert(res);
		if (res == "admintrue") {
			window.location = "manage.jsp";
		}else if(res == "workertrue"){
			window.location = "worker.jsp?name="+username;
	    }else if(res =="false") { 
			alert("用户名或密码错误，请重新输入");
		}
	});
	return false;
};













